cmake_minimum_required(VERSION 3.10)

project(RobotRender)

set(CMAKE_CXX_STANDARD 17)

set(RUNTIME_FILE)
set(ADDITIONAL_LIBS)
if(WIN32)
    if(MINGW)
        set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH};thirdparty/win64_mingw/assimp/lib/cmake/assimp-5.2)
        set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH};thirdparty/win64_mingw/sdl2/lib/cmake/SDL2)
        file(GLOB ASSIMP_RUNTIME_FILE thirdparty/win64_mingw/assimp/bin/*.dll)
        file(GLOB SDL2_RUNTIME_FILE thirdparty/win64_mingw/sdl2/bin/*.dll)
        set(RUNTIME_FILE ${ASSIMP_RUNTIME_FILE} ${SDL2_RUNTIME_FILE})
        set(ADDITIONAL_LIBS ${ADDITIONAL_LIBS};mingw32)
    elseif(MSVC)
        set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH};thirdparty/win64_msvc/assimp/lib/cmake/assimp-5.2)
        set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH};thirdparty/win64_msvc/sdl2/cmake)
        file(GLOB ASSIMP_RUNTIME_FILE thirdparty/win64_msvc/assimp/bin/*.dll)
        file(GLOB SDL2_RUNTIME_FILE thirdparty/win64_msvc/sdl2/bin/*.dll)
        set(RUNTIME_FILE ${ASSIMP_RUNTIME_FILE} ${SDL2_RUNTIME_FILE})
        set(ADDITIONAL_LIBS ${ADDITIONAL_LIBS};)
    endif()
elseif(UNIX)
    set(ADDITIONAL_LIBS ${ADDITIONAL_LIBS};dl)
endif()

# SDL2
find_package(SDL2 REQUIRED)

#Gl
find_package(OpenGL REQUIRED)

# Assimp
find_package(assimp REQUIRED)

add_library( IMGUI
    SHARED
        src/imgui/imgui.cpp
        src/imgui/imgui_demo.cpp
        src/imgui/imgui_draw.cpp
        src/imgui/imgui_impl_opengl3.cpp
        src/imgui/imgui_impl_sdl.cpp
        src/imgui/imgui_tables.cpp
        src/imgui/imgui_widgets.cpp)
target_include_directories( IMGUI
    PUBLIC
        include/imgui
        include)
target_link_libraries(IMGUI ${OPENGL_LIBRARIES})

add_executable( RobotRender
        src/main.cpp
        src/Mesh.cpp
        src/glad.c
        src/util.cpp
        src/UI.cpp
        src/SkyBox.cpp
        src/CoordDraw.cpp)

target_include_directories( RobotRender
    PUBLIC
        include
        interface
        ${SDL2_INCLUDE_DIRS}
        ${ASSIMP_INCLUDE_DIRS}
)
target_link_libraries( RobotRender
    ${ADDITIONAL_LIBS}
    ${SDL2_LIBRARIES}
    ${OPENGL_LIBRARIES}
    ${ASSIMP_LIBRARIES}
    IMGUI
)
add_custom_command(
        TARGET RobotRender
        POST_BUILD
        COMMAND
        ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/shader $<TARGET_FILE_DIR:RobotRender>/shader
)
add_custom_command(
        TARGET RobotRender
        POST_BUILD
        COMMAND
        ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/bits $<TARGET_FILE_DIR:RobotRender>/bits
)
if (RUNTIME_FILE)
    add_custom_command(
            TARGET RobotRender
            POST_BUILD
            COMMAND
            ${CMAKE_COMMAND} -E copy_if_different ${RUNTIME_FILE} $<TARGET_FILE_DIR:RobotRender>/
    )
endif()